package com.itheima.gateway.filter;

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

@Component
public class MyFilter implements GlobalFilter, Ordered {

    /*
        表示执行过滤器的方法
        ServerWebExchange交换机，存储了好多的方法
        GatewayFilterChain过滤器链
     */

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //过滤器的逻辑业务
        System.out.println("开始执行全局过滤器了ing......");
        System.out.println("你好吗？");
        System.out.println("开始执行全局过滤器了end......");
        //要进行放行操作，
        return chain.filter(exchange);
    }

    /*
       执行过滤器的优先级方法
       return的值越小，优先级越高
    */
    @Override
    public int getOrder() {
        return 0;
    }
}
